package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.NewEnergyAnalysis;
import com.ruoyi.mes.service.INewEnergyAnalysisService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 能耗统计分析Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/mes/energyAnalysis")
public class NewEnergyAnalysisController extends BaseController
{
    @Autowired
    private INewEnergyAnalysisService newEnergyAnalysisService;

    /**
     * 查询能耗统计分析列表
     */
    @PreAuthorize("@ss.hasPermi('mes:energyAnalysis:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewEnergyAnalysis newEnergyAnalysis)
    {
        startPage();
        List<NewEnergyAnalysis> list = newEnergyAnalysisService.selectNewEnergyAnalysisList(newEnergyAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出能耗统计分析列表
     */
    @PreAuthorize("@ss.hasPermi('mes:energyAnalysis:export')")
    @Log(title = "能耗统计分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewEnergyAnalysis newEnergyAnalysis)
    {
        List<NewEnergyAnalysis> list = newEnergyAnalysisService.selectNewEnergyAnalysisList(newEnergyAnalysis);
        ExcelUtil<NewEnergyAnalysis> util = new ExcelUtil<NewEnergyAnalysis>(NewEnergyAnalysis.class);
        util.exportExcel(response, list, "能耗统计分析数据");
    }

    /**
     * 获取能耗统计分析详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:energyAnalysis:query')")
    @GetMapping(value = "/{analysisId}")
    public AjaxResult getInfo(@PathVariable("analysisId") Long analysisId)
    {
        return success(newEnergyAnalysisService.selectNewEnergyAnalysisByAnalysisId(analysisId));
    }

    /**
     * 新增能耗统计分析
     */
    @PreAuthorize("@ss.hasPermi('mes:energyAnalysis:add')")
    @Log(title = "能耗统计分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewEnergyAnalysis newEnergyAnalysis)
    {
        return toAjax(newEnergyAnalysisService.insertNewEnergyAnalysis(newEnergyAnalysis));
    }

    /**
     * 修改能耗统计分析
     */
    @PreAuthorize("@ss.hasPermi('mes:energyAnalysis:edit')")
    @Log(title = "能耗统计分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewEnergyAnalysis newEnergyAnalysis)
    {
        return toAjax(newEnergyAnalysisService.updateNewEnergyAnalysis(newEnergyAnalysis));
    }

    /**
     * 删除能耗统计分析
     */
    @PreAuthorize("@ss.hasPermi('mes:energyAnalysis:remove')")
    @Log(title = "能耗统计分析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{analysisIds}")
    public AjaxResult remove(@PathVariable Long[] analysisIds)
    {
        return toAjax(newEnergyAnalysisService.deleteNewEnergyAnalysisByAnalysisIds(analysisIds));
    }
}
